<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\api\model\OrderCreate as OrderCreateModel;


/**
 * 创建订单接口
 */
class Ordercreate extends Api
{

    protected $noNeedRight = ['*'];

    //订单提交
    public function create()
    {

        try {
            $model = new OrderCreateModel();

            $data = [
                'user_id'=>$this->auth->id,
                'shop_id'=>input('shop_id',0),
                'money'=>input('money',0),
                'user_coupon_id'=>input('user_coupon_id',0),
                'create_type'=>0
            ];
            if (empty($data['shop_id'])){
                $this->error('缺少参数店铺id');
            }
            if (empty($data['money'])){
                $this->error('缺少参数付款金额');
            }
            $res = $model->ordercreate($data);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }

        $this->success('',$res);
    }

    //订单计算
    public function calculate()
    {
        try {
            $model = new OrderCreateModel();

            $data = [
                'user_id'=>$this->auth->id,
                'shop_id'=>input('shop_id',0),
                'money'=>input('money',0),
                'user_coupon_id'=>input('user_coupon_id',0),
                'create_type'=>0
            ];
            if (empty($data['shop_id'])){
                $this->error('缺少参数店铺id');
            }
            if (empty($data['money'])){
                $this->error('缺少参数付款金额');
            }
            $res = $model->calculate($data);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('提交成功',$res);


    }
}